package org.bot.plugin.window.event;

import org.bot.api.event.DataStorage;
import org.bot.api.event.EventName;
import org.bot.api.util.StringUtil;
import org.bot.api.event.Events;
import org.bot.api.flow.FlowNode;
import org.bot.plugin.window.tool.WindowOperate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 沧月
 * @create 0014 2023/10/14 20:05
 * @description <拷贝内容到剪切板>
 */
@Component
@EventName("拷贝（window）")
public class WindowCopy implements Events {

    @Autowired
    WindowOperate operate;

    @Override
    public Object exec(FlowNode note, DataStorage data) {
        Object value;
        if (StringUtil.isNull(note.getDataIndex())) {
            value = note.getArg();
        } else {
            value = data.get(note.getDataIndex());
        }
        if (value == null) {
            return true;
        }
        return operate.copy(value.toString());
    }
}
